INCLUDE(ExternalProject)

SET(bullet_PREFIX ${PROJECT_BINARY_DIR}/bullet)

SET(bullet_CMAKE_ARGS 
    -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
    -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
    -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
	-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
    -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
    -DCMAKE_DEBUG_POSTFIX=_d
    -DINSTALL_LIBS=ON
    -DUSE_MSVC_RUNTIME_LIBRARY_DLL=ON
    -DBUILD_DEMOS=OFF
    -DBUILD_CPU_DEMOS=OFF
    -DBUILD_OPENGL3_DEMOS=OFF
    -DBUILD_BULLET2_DEMOS=OFF
    -DBUILD_BULLET3=OFF
    -DBUILD_EXTRAS=OFF
    -DBUILD_UNIT_TESTS=OFF
)

#IF(CMAKE_COMPILER_IS_GNUCXX)
#    # Needs fpic to link in shared lib on Linux with GCC
#    LIST(APPEND bullet_CMAKE_ARGS -DCMAKE_CXX_FLAGS=-fPIC)
#ENDIF(CMAKE_COMPILER_IS_GNUCXX)

ExternalProject_Add(bullet
    PREFIX ${bullet_PREFIX}
    
    DOWNLOAD_DIR ${POLYCODE_DEPS_DOWNLOAD_DIR}

    URL https://github.com/bulletphysics/bullet3/archive/2.83.5.tar.gz
    URL_MD5 87e42fad2216801d5cef0af7e547ce08

    INSTALL_DIR ${POLYCODE_DEPS_MODULES_PREFIX} 
    CMAKE_ARGS ${bullet_CMAKE_ARGS}
)
